﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MakeIT_Bill_Maker
{
    public partial class frmReport : Form
    {
        private Database.DatabaseConnection conn = new Database.DatabaseConnection();

        public frmReport()
        {
            InitializeComponent();
        }

        private void btnReport_Click(object sender, EventArgs e)
        {
            //string sql = "SELECT * FROM Users u LEFT JOIN  UsersMonthly m ON m.BillNo = u.AptNo  WHERE MONTH(CurrReadDate) = '" + cmbMonth.Text + "' AND  YEAR(CurrReadDate) = '" + cmbyear.Text + "'   ORDER BY PrevReadDate DESC";
            string sql = "SELECT * FROM Users u LEFT JOIN  UsersMonthly m ON m.BillNo = u.AptNo  WHERE MONTH(CurrReadDate) = '" + cmbMonth.Text + "' AND  YEAR(CurrReadDate) = '" + cmbyear.Text + "'";
            DataSet dataset = conn.Show(sql);
            DataTable dt = dataset.Tables[0];

            string sql1 = "SELECT TAddress,TTel,TimeFrom,TimeTo,Days FROM OtherFixed WHERE Index=1";
            DataSet dataset1 = conn.Show(sql1);
            DataTable dt1 = dataset1.Tables[0];

            if (dt.Rows.Count > 0)
            {
                Report.PdfReport r = new Report.PdfReport();
                r.printPdf(dt, dt1, (int.Parse(cmbMonth.Text)-1).ToString(), cmbyear.Text);
            }
            else
            {
                MessageBox.Show("No bill for this month.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void frmReport_Load(object sender, EventArgs e)
        {
            int year;
            for(year = 2011; year < 2212; year++)
            {
                cmbyear.Items.Add(year);
            }

            cmbyear.Text = DateTime.Now.Year.ToString();
            cmbMonth.Text = DateTime.Now.Month.ToString();
        }
    }
}
